package dao

import (
	"ssims/models"
)

func GetAllPeople(people map[string]interface{}) (error, []models.People, int64) {
	var peopleData []models.People
	page := people["page"].(int)
	pageSize := people["limit"].(int)
	searchId := people["searchId"].(string)
	var total int64
	err := db.Table("people").Select("people_id", "user_id", "people_name", "description", "create_time").Where("people_id like ? and is_del = false", searchId+"%").Count(&total).Offset((page - 1) * pageSize).Limit(pageSize).Find(&peopleData).Error
	return err, peopleData, total
}

func DelPeople(id string) error {
	err := db.Table("people").Where("people_id = ?", id).Update("is_del", true).Error
	return err
}

func UpdatePeople(people models.People) error {
	err := db.Table("people").Select("people_id", "user_id", "people_name", "description", "create_time").Where("people_name = ?", people.PeopleName).Updates(&people).Error
	return err
}

func AddPeople(people models.People) error {
	err := db.Table("people").Select("people_id", "user_id", "people_name", "description", "create_time", "is_del").Create(&people).Error
	return err
}
